package com.erclab.internal.xpresso.xml;

import java.util.ArrayList;

import com.erclab.internal.xpresso.formelements.FormElement;
import com.erclab.internal.xpresso.forms.Form;

public class XmlFormHelper {

	public static void writeFormTags(Form theForm, StringBuffer xml) {
		xml.append("<title>");
		xml.append(theForm.getTitle());
		xml.append("</title>");

		xml.append("<uniqueKeyName>");
		xml.append(theForm.getUniqueKeyName());
		xml.append("</uniqueKeyName>");

		xml.append("<parentKeyName>");
		xml.append(theForm.getParentKeyName());
		xml.append("</parentKeyName>");
		
		if (theForm.getValidationError() != null){
			xml.append("<validationError>");
			xml.append(theForm.getValidationError().toString());
			xml.append("</validationError>");
		}
	}

	public static void writeFormElementTags(Form theForm, StringBuffer xml) {
		ArrayList elements = theForm.getFormElements();
		for (int i =0; i < elements.size(); i++){
			FormElement e = (FormElement)elements.get(i);
			xml.append("<formElement>");
			
			xml.append("<label>");
			xml.append(e.getLabel());
			xml.append("</label>");

			xml.append("<id>");
			xml.append("Field" + e.getIdFormElement());
			xml.append("</id>");
			
			xml.append("<dataType>");
			xml.append(e.getDataType());
			xml.append("</dataType>");
			
			xml.append("<parameters>");
			xml.append(e.getParameters());
			xml.append("</parameters>");

			xml.append("<DestinationColumn>");
			xml.append(e.getDestinationColumn());
			xml.append("</DestinationColumn>");			

			xml.append("<Style>");
			xml.append(e.getStyle());
			xml.append("</Style>");				
			
			xml.append("</formElement>");
		}
	}	
	
}
